package io.renren.modules.generator.service.impl;

import io.renren.modules.sys.dao.SysUserDao;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.generator.dao.WebRotationDao;
import io.renren.modules.generator.entity.WebRotationEntity;
import io.renren.modules.generator.service.WebRotationService;


@Service("webRotationService")
public class WebRotationServiceImpl extends ServiceImpl<WebRotationDao, WebRotationEntity> implements WebRotationService {

    @Autowired
    private WebRotationDao webRotationDao;

    @Autowired
    private SysUserDao sysUserDao;

    @Override
    public Integer getMaxSort() {
//        webRotationDao.selectOne(new QueryWrapper<>().orderByDesc("rotation_sort).last("limit 1"));
        Integer integer = webRotationDao.queryMaxSort();
        return integer;
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
      IPage<WebRotationEntity> page = this.page(
        new Query<WebRotationEntity>().getPage(params),
          new QueryWrapper<WebRotationEntity>().like(StringUtils.isNotBlank(key),"rotation_name", key).
            orderByAsc("rotation_sort")
        );

        return new PageUtils(page);
    }

    @Override
    public List<WebRotationEntity> getSideList() {
        List<WebRotationEntity> list= webRotationDao.getSideList();
        return list;
    }

}
